<template>
  <el-form-item label="关闭时的值">
    <el-input v-model="optionModel.inactiveValue"
      @change="updateAssignValue('inactiveValue', 2)">
    </el-input>
  </el-form-item>
  <el-form-item :label="i18nt('designer.setting.inactiveText')">
    <el-input v-model="optionModel.inactiveText"></el-input>
  </el-form-item>
</template>

<script>
  import i18n from "@/utils/i18n"

  export default {
    name: "inactiveText-editor",
    mixins: [i18n],
    props: {
      designer: Object,
      selectedWidget: Object,
      optionModel: Object,
    },
    watch: {
      selectedWidget: {
        handler(val) {
          const { optionModel } = this
          if (!this.optionModel.hasOwnProperty("inactiveValue")) {
            this.optionModel.inactiveValue = 2
          }
        },
        deep: false,
        immediate: true
      },
    },
    methods: {
      /**
       * 更新的开关组件的值
       * 
       * @param field 字段
       * @param defValue 默认值
       */
      updateAssignValue (field, defValue) {
        const { valueType } = this.optionModel
        const targetValue = this.optionModel[field]
        if (valueType === 'number') {
          if (Number.isNaN(Number(targetValue))) {
            this.optionModel[field] = defValue
          } else {
            this.optionModel[field] = Number(targetValue)
          }
        } else {
          this.optionModel[field] = targetValue + ''
        }
      }
    }
  }
</script>

<style scoped>

</style>
